#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList; 
Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L1, LinkList &L2, int n1, int n2, int n3)
{
	LNode *t1 = L1;
	for(int i = 0; i < n1; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t1->next;
		t1->next = p;
		t1 = p;
	}
	LNode *t2 = L2;
	for(int i = 0; i < n2; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t2->next;
		t2->next = p;
		t2 = p;
	}
	
	for(int i = 0; i < n3; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t1->next;
		t1->next = p;
		t2->next = p;
		t1 = p;
		t2 = p;
	}
	return OK;
}

int Length(LinkList L)
{
	LNode *p = L->next;
	int n = 0;
	while(p)
	{
		n ++;
		p = p->next;
	}
	return n;
}
LinkList Search_Common(LinkList L1, LinkList L2)
{
	/***************Begin****************/
    int len1 = Length(L1);
    int len2 = Length(L2);
    
    LNode *p = L1->next; // L1的第一个节点
    LNode *q = L2->next; // L2的第一个节点
    
    // 调整较长的链表的指针，使其剩余长度与另一个链表相同
    int gap = abs(len1 - len2);
    if (len1 > len2) {
        for (int i = 0; i < gap; ++i) {
            p = p->next;
        }
    } else {
        for (int i = 0; i < gap; ++i) {
            q = q->next;
        }
    }
    
    // 同步遍历，寻找第一个公共节点
    while (p && q) {
        if (p == q) { // 地址相同即为公共节点
            return p;
        }
        p = p->next;
        q = q->next;
    }
    
    return NULL; // 没有公共节点
    /****************End***************/
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L1, L2;
	Init(L1);
	Init(L2);
	
	int n1, n2, n3;
	cin >> n1 >> n2 >> n3;
	
	Create(L1, L2, n1, n2, n3);
	
	
	LNode *p = Search_Common(L1, L2);
	if(p) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}